home *** CD-ROM | disk | FTP | other *** search
- -- 2000.03.12
- -- Clive Green <clivegreen@atlas.co.uk>
-
- ------------------------------------------------------------------------------------------------------
-
- -- This is just a repository of programme settings obtained from external text files.
-
- -- The access method getData() needs to be passed a list of the form:
- -- [#set:<#setName>{,#item:<#itemName>}]
-
- -- the method setDataItem needs to be passed a list of the form:
- -- [#set:<#setName>,#item:<#itemName>, #value:<#propList>]
-
- ------------------------------------------------------------------------------------------------------
-
- -- declare properties:
- property main -- main code directory object
- property utilityMethods -- miscellaneous functions
- property rootPath -- the runtime parent path of the projector/stub
- property dataLibList -- linear list of linked data castlibs
- property dataFiles -- a list of known data file #references
- property dataSet -- data storage - a propList of propLists!
-
- ------------------------------------------------------------------------------------------------------
-
- on new me,L
-
- -- (1) extract and check arguments:
-
- -- check for a parameter list:
- if ilk(L) <> #propList then return [#error:#noParamListSupplied, #msg:"dataManager:new"]
-
- -- a reference to the parent codebase is REQUIRED:
- main = L[#main]
- if (ilk(main) <> #instance) then return [#error:#noMainObjectSupplied, #msg:"dataManager:new"]
-
- --------------------
-
- -- store literals:
-
- -- which linked castlibraries contain data used by the programmme?
- dataLibList = ["data"]
-
- --------------------
-
- -- (2) import data held in castlibrary fields:
-
- -- pull in utility methods:
- utilityMethods = main.getUtilityMethods()
-
- -- store internally held data:
- dataSet = [:]
-
- -- recurse over all known data castlibs:
- repeat with i in dataLibList
-
- -- get the ith listed castlib's number:
- c = castlib(i).number
-
- -- recurse over all of library c's field members:
- repeat with j = 1 to the number of members of castlib c
-
- -- examine fields only:
- n = member(j,c).number
- if member(n).type <> #field then next repeat
-
- -- convert each field's text into a data list:
- t = member(n).text
- L = utilityMethods.listFromText(t)
-
- -- stored listing:
- n = symbol(member(n).name)
- dataSet[n] = L
-
- end repeat
-
- end repeat
-
- --------------------
-
- -- pass back my address:
- return me
-
- ----------------------------------------------------------------------------------------------------
-
- on setRootPath me,p
-
- -- store the path string supplied as is:
- rootPath = p
-
- ----------------------------------------------------------------------------------------------------
-
- on getRootPath me
-
- -- pass back the parent path of the projector/stub:
- return rootPath
-
- ----------------------------------------------------------------------------------------------------
-
- on getExternalData me
-
- -- import data held in external text files:
-
- -- (1) obtain the fileIO service:
- xm = main.getXtrasManager()
- fileIO = xm.getFileIOxtra()
-
- if (ilk(fileIO) <> #instance) then return ¬
- [#error:#xtraControllerMissing, #msg:"dataManager:new needs fileIOxtra"]
-
- --------------------
-
- -- (2) what text files contain data used by the programme?
- L = []
- add L,#soundFX
- add L,#conditionElements
- add L,#conditionGroups
- add L,#outcomes
- add L,#glueCalls
- add L,#callBindings
- add L,#macInstallerPaths
- add L,#pcInstallerPaths
-
- dataFiles = L
-
- --------------------
-
- -- (3) get a listing of all known filePaths:
- fp = me.getData([#set:#filePaths])
-
- -- we need a valid filePaths listing:
- if stringP(fp[#error]) then return fp
-
- --------------------
-
- -- (4) attempt to acquire all file-based data:
-
- -- process all data files:
- repeat with i in dataFiles
-
- -- what is the filepath of file #i?
- f = fp[i][#filePath]
-
- -- obtain a platform-specific version of this filePath:
- f = utilityMethods.parseFilePath(f)
-
- -- a valid path string is required:
- if not stringP(f) then return f
-
- --------------------
-
- -- each filePath is given relative to the application's root stub/projector:
- f = rootPath & f
-
- -- attempt to obtain the text for this file:
- t = fileIO.importTextFile([#filePath:f, #type:#readOnly])
-
- -- ALL DATA IS REQUIRED -
- -- fail on first unsuccessful retrieval:
- if not stringP(t) then return t
-
- --------------------
-
- -- now attempt to render a lingo list:
- L = utilityMethods.listFromText(t)
- if not listP(L) then return [#error:#badTextData, #msg:i]
-
- -- add this data as a named item:
- dataSet[i] = L
-
- end repeat
-
- -- flag successful operation:
- return me
-
- ----------------------------------------------------------------------------------------------------
-
- on getData me,L
-
- -- need a list of arguments to be supplied:
- if ilk(L) <> #propList then return [error:#e1005]
-
- -- also need a dataSet to continue!
- if ilk(dataSet) <> #propList then return [error:#e1006]
-
- -- set specification is needed:
- xSet = L[#set]
- if voidP(xSet) then return [error:#e1007]
-
- -- an item specification is optional:
- xItem = L[#item]
-
- -- set reference must be a symbol:
- if not symbolP(xSet) then return [error:#e1010]
-
- -- extract the list of data items called #xSet:
- xData = dataSet[xSet]
-
- -- the dataSet must exist!
- if ilk(xData) <> #propList then return [error:#e1008]
-
- -- resolve further if an item reference is provided:
- if symbolP(xItem) then
-
- -- extract the data item called #xItem:
- xData = xData[xItem]
-
- -- if an item ref was supplied, then it must resolve to an actual data item:
- if voidP(xData) then return [error:#e1009]
-
- end if
-
- --------------------
-
- -- pass back A COPY OF the data item to the caller:
- if listP(xData) then xData = duplicate(xData)
- return xData
-
- ----------------------------------------------------------------------------------------------------
-
- on setDataItem me,L
-
- -- quickie implementation:
-
- -- need a list of arguments to be supplied:
- if ilk(L) <> #propList then return [error:#e1005]
-
- --------------------
-
- -- which set is to be updated?
- xSet = L[#set]
-
- -- which item is to be changed?
- xItem = L[#item]
-
- -- what is the new value to be set?
- xValue = L[#value]
-
- -- extract the list of data items called #xSet:
- xData = dataSet[xSet]
-
- --------------------
-
- -- set the new value:
- xData[xItem] = xValue
-
- ----------------------------------------------------------------------------------------------------